<script>
$(document).ready(function(){
	$(".news a").css({"color":"blue"});
	$('#checkall').change(function() {
			var checkboxes = $(this).closest('.table').find(':checkbox');
			if($(this).is(':checked')) {
					checkboxes.attr('checked', 'checked');
			} else {
					checkboxes.removeAttr('checked');
			}
	});
	$("#delete_many").click(function(){
		if($(":checkbox[name*='check']").is(':checked')){
			return true;
		}else{
			alert("Vui lòng chọn dữ liệu cần xóa !");
			return false;
		}
	});
});
function delete_news(id) 
{
		var choose = confirm("Bạn có chắc muốn xóa tin này ?");
		if(choose == true){
			 window.location.assign("/back/admin/delete/"+id);
		}else{
			return false;
		}
}
function show_hidden(id,show_id){
	var href = window.location.href;
	$.get("back/admin/show/"+id+"/"+show_id).success(function(){
			$(".ITwrapper").load(href+' .ITwrapper');
	});
}
</script>
<section class="content-header">
	<h1>Danh sách bài viết</h1>
	<nav>
		<ul>
			<li class="active"><a href="#">Danh mục bài viết</a></li>
			<li><a href="#">Danh sách bài viết</a></li>
		</ul>
	</nav>
</section><!--content-header-->
<section class="content-view">
	<section class="advance">
		<section class="search">
			<form method="get" action="back/admin/search">
				<select name="option">
					<option value="1">Danh mục sản phẩm</option>
				</select>
				<input type="text" name="key" id="key" placeholder="Từ khóa.........." class="txtkey"value="<?php echo isset($key)?$key:'';?>"/>
				<input type="submit" value="Tìm kiếm" name="search" class="btnsearch"/>
			</form>
		</section><!--End Search-->
			<form method="post" action="back/admin/delete_many">
				<section class="tool">
					<ul>
						<li><button><a href="back/auth/create">Thêm mới</a></button></li>
						<li><input type ="submit" value="Xóa nhiều" name="delete_many" id="delete_many"></li>
						<li><input type ="submit" value="Hiển thị" id="show"></li>
					</ul>
				</section><!--End tool-->
	</section><!--End advance-->
	<section class="table">
		<table>
			<tr>
				<th>STT</th>
				<th><input type="checkbox" id="checkall"></th>
				<th>Tên bài viết</th>
				<th>Danh mục cha</th>
				<th>Ngày tạo</th>
				<th>Ngày sửa</th>
				<th>Người tạo</th>
				<th>Người sửa</th>
				<th>Lượt xem</th>
				<th>Vị trí</th>
				<th>Hiển thị</th>
				<th>Thao tác</th>
				<th>Mã</th>
			</tr>
			<tbody>
			<?php
				if(count($news) > 0){
					foreach($news as $news_info){	
			?>
			
				<tr>
					<td><?php echo $stt;?></td>
					<td><input type="checkbox" name="check[]" value="<?php echo $news_info['id'];?>"></td>
					<td><a href="#"><?php echo $news_info['news_name'];?></a></td>
					<td><?php echo $news_info['parent_id'];?></td>
					<td><?php echo inttodate($news_info['create_date']);?></td>
					<td><?php echo inttodate($news_info['edit_date']);?></td>
					<td  align="center"><a href="#"><?php echo $news_info['user_create'];?></a></td>
					<td  align="center"><?php echo $news_info['user_edit'];?></td>
					<td><?php echo $news_info['count_view'];?></td>
					<td><input type="number" id="vitri" name="vitri" value="1"></td>
					<td  align="center"><img src="<?php echo $news_info['show']==1?'/public/back/img/check.ico':'/public/img/hidden.ico';?>" title="<?php echo $news_info['show']==1?'Ẩn':'Hiện thị';?>" onclick="show_hidden(<?php echo $news_info['id'];?>,<?php echo $news_info['show'];?>)"/></td>
					<td><a href="back/admin/edit" title="Edit"><img src="/public/back/img/edit.ico"/></a>&nbsp;&nbsp;&nbsp;<img src="/public/back/img/delete.ico" onclick="delete_news(<?php echo $news_info['id'];?>)"/></td>
					<td>1</td>
				</tr>
				<?php $stt++; }
				}else{
					echo"<tr><td colspan ='13' align=center>Không có dữ liệu</td></tr>";
				}?>
			</tbody>
		</table>
	</section><!--End table-->
	<section class="pagination">
		<?php echo $link;?>
	</section><!--End pagination-->
</section><!--End content-view-->
</form>